package com.tenement.controller;

import com.tenement.common.Axios;
import com.tenement.enums.RespBusiness;
import com.tenement.service.UserRoleService;
import com.tenement.vo.UserRoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 *  控制层。
 *
 * @author BertXie
 * @since 1.0.1
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/userRole")
@Api(tags = "用户角色管理")
public class UserRoleController {


    private final UserRoleService userRoleService;

    @ApiOperation("为用户分配角色")
    @PutMapping("operator")
    public Axios operator(@RequestBody UserRoleVo userRoleVo) {
        return userRoleService.operator(userRoleVo) ? Axios.success("分配成功") : Axios.error(RespBusiness.FAIL);
    }

    @ApiOperation("获取用户的角色")
    @GetMapping("roleIds/{userId}")
    public Axios roleIds(@PathVariable Long userId) {
        return Axios.success(userRoleService.roleIds(userId));
    }
}
